/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var insertGreatestCommonDivisors = function(head) {
    if(head.next === null) return head
    const getCommonDivisors = (m, n) => {
        let temp = 0
        while(temp = m % n) {
            m = n
            n = temp
        }
        return n
    }
    let pre = head, tail = head.next
    while(tail) {
        let node = new ListNode()
        node.val = getCommonDivisors(pre.val, tail.val)
        pre.next = node
        node.next = tail
        pre = tail
        tail = tail.next
    }
    return head
};